import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

public class QLearningDriver {

	public static final int NUMBER_OF_STEPS = 1000000;
	public static final int NUMBER_OF_CHANNELS = 1;
	public static final int NUMBER_OF_NODES = 10;

	public static void main(String[] args) {
		System.out.println("This time it's personal!\n\n");
		List<Node> nodes = new ArrayList<Node>();
		for (int i = 0; i < NUMBER_OF_NODES; i++) {
			nodes.add(new Node("Node " + (i + 1)));
		}
		Environment currentEnvironment = new Environment(NUMBER_OF_CHANNELS);
		for (Node node : nodes) {
			node.environment = currentEnvironment;
		}
//		try {
//			PrintWriter out = new PrintWriter(new FileWriter("uberresults.txt"));
		
			for (int i = 0; i < NUMBER_OF_STEPS; i++) {
				currentEnvironment.numberOfInterferences = 0;
				System.out.println("STARTING STEP " + (i + 1));
//				System.out.println("--------------");
//				System.out.println("Environment:");
//				for (Channel ch : currentEnvironment.channels) {
//					System.out.println(ch);
//				}
				for (Node node : nodes) {

					node.iterate();
				}
//				System.out.println("Current utilization: " + currentEnvironment.channelUsage + "/" + currentEnvironment.channels.size());
//				System.out.println("Current interferences: " + currentEnvironment.interferingChannels.size());
//				out.println(i + "," + currentEnvironment.channelUsage + "," + currentEnvironment.interferingChannels.size());
//				System.out.println("ENDING STEP " + (i + 1));
//				System.out.println("++++++++++++++");
				System.out.println("Total number of interferences " + currentEnvironment.numberOfInterferences);
			}
			
			for (Node node : nodes) {
				System.out.println("++++++++");
				System.out.println(node.name);
				node.printQ();
			}
//			out.close();
//		} catch (IOException e) {
//			e.printStackTrace();
//		}
	}

}
